package com.simon.card;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;
/**
 * 2016年04月30日00:34:33
 * @author liming
 * 牌的初始化和洗牌操作方法
 */
public class CardUtils {
	
	//定义花色
	public static final String[] COLORS=new String[]{"方块","梅花","红桃","黑桃"};
	//定义花色枚举
	public static final String[] CARDVALUES=new String[]{"A","2","3","4","5","6","7","8","9","10","J","Q","K","King_Small","King_Big"};
	
	
	public ArrayList<Card> initCardGroup(){
		//定义一副牌
		 ArrayList<Card> groupCard=new ArrayList<Card>();
		//加入A~K
		for(int i=0;i<13;i++){
		  for (int j=0;j<4;j++){ 
		    //生成一张牌的对象
		    Card card=new Card();
		    card.id=i;
		    card.color=COLORS[j];
		    card.number=CARDVALUES[i];
		    //将对象加入牌组
		    groupCard.add(card);
		  }
		}
		//加入大小王
		Card card_k1=new Card();
		card_k1.id=13;
		card_k1.color="King_Small";
		card_k1.number="King_Small";
		groupCard.add(card_k1);
		Card card_k2=new Card();
		card_k2.id=14;
		card_k2.color="King_big";
		card_k2.number="King_big";
		groupCard.add(card_k2);

	return groupCard;
}
	public ArrayList<Card> flushCardsGroup(List<Card> groupCard){
	     ArrayList<Card> result=new ArrayList<Card>();
	     while(groupCard.size()>0){
	        int size=groupCard.size();
	        //以size为限，生成0~size之间的随机数
	        Random r=new Random();
	        int index=r.nextInt(size);
	        
	        //对index做个检查  不知道这里为什么要做检查，导致其他的一些问题
	        //if(index>0){index=0;}
	        //if(index>size-1){index=size-1;}
	        //index就是捡出来的牌，加到新的数组中，从原来数组中删除
	        Card card=groupCard.get(index);
	       
	        result.add(card);
	        groupCard.remove(index);
	        
	     }
	     
	    return result;
	}
	
	
}
